#ifndef QSFMLWIDGET_H
#define QSFMLWIDGET_H

/*!
 * \file      qsfmlwidget.h
 * \brief     Widget to use SFML stuff.
 * \author    SFML Staff
 * \author    Duriez Franck
 * \version   0.3
 */

#include <SFML/Graphics.hpp>
#include <QWidget>
#include <QTimer>
#include <QPaintEvent>

/*!
 * \class    QSFMLWidget
 * \brief    Widget to use SFML stuff.
 */
class QSFMLWidget : public QWidget, public sf::RenderWindow /*{{{*/
{
public :

	/*!
	 * \brief Constructor.
	 * \param parent    : parent of the widget
	 * \param position  : position of the widget
	 * \param size      : size of the widget
	 * \param frameTime : frame duration, in milliseconds (0 by default)
	 */
	QSFMLWidget(QWidget* parent, const QPoint& position,
	            const QSize& size, unsigned int frameTime = 0);

	/*!
	 * \brief Destructor.
	 */
	virtual ~QSFMLWidget();

	void refresh();
	float* getElapsedTime();

	virtual void resizeEvent(QResizeEvent* e);

protected:

	/*!
	 * \brief Return the paint engine used by the widget to draw itself.
	 */
	virtual QPaintEngine* paintEngine() const;

	/*!
	 * \brief Called when the widget is shown.
	 *        We use it to initialize our SFML window.
	 */
	virtual void showEvent(QShowEvent*);

	/*!
	 * \brief Called when the widget needs to be painted.
	 *        We use it to display a new frame.
	 */
	virtual void paintEvent(QPaintEvent*);

private :

	/*!
	 * \brief Notification for the derived class that moment is good
	 *        for doing initializations.
	 */
	virtual void initialize() = 0;

	/*!
	 * \brief Notification for the derived class that moment is good
	 *	    for doing its update and drawing stuff.
	 */
	virtual void update() = 0;

	QTimer    m_timer; ///< Timer used to update the view
	bool      m_initialized; ///< Tell whether the SFML window has been initialized or not
	sf::Clock m_clock; ///< Timer used to measure the time between two update

protected:
	float     m_elapsed_time; ///< Infinitesimal part of time
}; /*}}}*/

#endif // QSFMLWIDGET_H
